package com.datn.DataAccess;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import com.datn.activity.NearLocationActivity;
import com.datn.activity.R;
import com.datn.utils.AlertCustom;
import com.datn.utils.FileUtils;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import android.widget.Toast;

public class DatabaseHelper extends SQLiteOpenHelper{

	
		
		private Context context;
	
		public DatabaseHelper(Context context, String name,
				CursorFactory factory, int version) {
			super(context, name, factory, version);
			// TODO Auto-generated constructor stub
			this.context=context;
		}

		public void onCreate(SQLiteDatabase db) {
			// TODO Auto-generated method stub
			FileUtils file=new FileUtils(context);
	        StringBuilder sb=new StringBuilder();
	        try {
				ArrayList<String> allLine= file.readDatabase();
				for (int i = 0; i < allLine.size(); i++) {
					db.execSQL(allLine.get(i));
					Log.v("NEW DATABASE", "EXECUTE SQL:"+allLine.get(i));
				}
				
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
			// TODO Auto-generated method stub
			onCreate(db);
		}		
		
		
	}